package ac.zlf.maven.template.controller;


import ac.zlf.maven.template.App;
import ac.zlf.maven.template.service.UserService;
import ac.zlf.maven.template.view.Item1View;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 主页
 */
@FXMLController
public class MainController extends ParentController {

    @FXML
    private HBox hBoxTitle;
    @Autowired
    private UserService userService;

    /**
     * 调用在根元素之后初始化一个控制器。
     * 完全处理。
     *
     * @param location  用于解析根对象的相对路径的位置
     *                  <tt>空</tt>如果位置未知。
     * @param resources 用于本地化根对象的资源，或<tt>null</tt> if
     */
    public void initialize(URL location, ResourceBundle resources) {
        System.out.println(userService.findAll());
    }

    @FXML
    public void handlerBtnClick(ActionEvent event) {
        Button btnSource = (Button) event.getSource();
        btnSource.setText("I am clicked!");
//        Util.openNewWindow(item1Controller, GUIState.getStage(), "view/item1.fxml", "item 1", null, (windowEvent) -> {
//            Stage stage = (Stage) windowEvent.getSource();
//            System.out.println(stage.getUserData());
//        });
        App.showView(Item1View.class, Modality.APPLICATION_MODAL);
    }

}